package com.LC._242;

import javax.lang.model.type.ReferenceType;
import java.util.HashMap;

public class Solution {
    //大小写是否敏感
    public boolean isAnagram(String s, String t) {
        HashMap<Character, Integer> Smap = new HashMap<>();//key : value == Character:Integer
        HashMap<Character, Integer> Tmap = new HashMap<>();
        if (s.length() != t.length()) {
            return false;
        }
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            char b = t.charAt(i);

            if (Smap.containsKey(c) == false) {
                Smap.put(c, 1);
            }
            Smap.put(c, Smap.get(c) + 1);

            if (Tmap.containsKey(b) == false) {
                Tmap.put(b, 1);
            }
            Tmap.put(b, Tmap.get(b) + 1);

        }
        if (Smap.size() != Tmap.size()) return false; ///计算 hashMap 中键/值对的数量
        for (Character c : Smap.keySet()) {
            if (Tmap.containsKey(c) == false) {
                return false; //判断是否有相应的key值
            }
            if (Smap.get(c).equals(Tmap.get(c)) != true) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        String  c = "anagram", t = "nagaram";
       boolean res = s.isAnagram(c,t);
        System.out.println(res);

    }
}
